<?php

namespace App\Http\Middleware;

use Closure;
use Jenssegers\Agent\Agent;
use Illuminate\Support\Facades\Redirect;

class MobileDetect {
	/**
	 * Handle an incoming request.
	 *
	 * @param \Illuminate\Http\Request $request
	 * @param \Closure $next        	
	 * @return mixed
	 */
	public function handle($request, Closure $next) {
		$agent = new Agent();
		if($agent->isMobile()) {
			return Redirect::to('/mobile/' . $request->path());
		}
		return $next($request);
	}
}
